package top.ivansong92.example.leetcode.learning.data.struct.array.sort;

/**
 * 冒泡排序
 */
public class BubbleSort implements ArraySort {
    @Override
    public void sort(int[] array) {
        if (array == null || array.length < 2) {
            return;
        }
        for(int i = 0; i < array.length; i ++) {
            for(int j = 1; j < array.length - i; j ++) {
                int a1 = array[j - 1];
                int a2 = array[j];
                if (a1 <= a2) {
                    continue;
                }
                array[j] = a1;
                array[j - 1] = a2;
            }
        }
    }
}
